{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">数据库还原</li>
            <li class=""><a href="{:url('/admin/database/index/type/export')}">数据库备份</a></li>
        </ul>
        <div class="layui-tab-content">

            <div class="layui-form layui-form-pane">
                <div class="layui-inline">
                    <label class="layui-form-label">选项</label>
                    <div class="layui-input-inline">
                 <select class="form-control input-sm setStatus" name="status">
                <option value="0">批量操作</option>
                <option value="1">删除备份</option>
              </select>
                    </div>
                </div>
                
                <div class="layui-inline">
                    <button class="layui-btn"><i class="layui-icon">&#xe616;</i> 应用</button>
                </div>
            </div>
            <hr>

       
                <div class="layui-tab-item layui-show">
                <table class="layui-table">
                  <thead>
                  <tr>
                    <th><input type="checkbox" class="check-all"></th>
                    <th>备份名称</th>
                    <th>卷数</th>
                    <th>压缩</th>
                    <th>数据大小</th>
                    <th>备份时间</th>
                    <th>状态</th>
                    <th>操作</th>      
                  </tr>
                  </thead>
                  <tbody>
                  {volist name="list" id="data"}
                  <tr>
                    <td ><input type="checkbox" class="check" name="ids" value="{$data['time']}" /></td>
                    <td>{$data.time|date='Ymd-His',###}</td>
                    <td>{$data.part}</td>
                    <td>{$data.compress}</td>
                    <td>{$data.size|format_bytes}</td>
                    <td>{$key}</td>
                    <td>-</td>
                    <td class="action">
                        <a class="db-import" href="{:url('import?time='.$data['time'])}">还原</a>
                    </td>

                  </tr>
                  {/volist}
                  
                  </tbody>
                  <thead>
                  
                  </thead>
                  
                </table>
                
                </div>
        </div>
    </div>
</div>

<script type="text/javascript">
var url;
var tables;
  $('document').ready(function(argument){
    //全选、取消全选的事件
    $("th .selectAll").click(function(){
      if(this.checked){
        $(".check").each(function(){this.checked=true;});
      }else{
        $(".check").each(function(){this.checked=false;});
      }
    });
    //设置状态方法
    $('.layui-btn').click(function(){
      setStatus = $(".setStatus").val();
      var ids = new Array();//声明一个存放id的数组
      $("[name='ids']:checked").each(function(){
        ids.push($(this).val());
      });
      if(setStatus==0){
 
		layer.msg('请选择操作类型');
        return;
      }
      if(ids.length==0){
		layer.msg('请选择要操作的数据');
        return;
      }
      
      $.ajax({
        cache:true,
        type :"POST",
        url  :'{:url('del')}',
        data :{time:ids},
        async:false,
           success:function(data){
            if(data.code){
              alert(data.msg);
              setTimeout(function(){
                location.href=data.url;
              },1000);
            } else {
              alert(data.msg);
            }
           },
           error:function(request){
			 layer.msg('页面错误');
           }
      });        
    });

     // select选中
    $(".filterStatus").val("{$Think.get.status ?? '0'}");

    $(".db-import").click(function(){
            var self = this, status = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;
        
            function success(data){
                if(data.code){
                    if(data.data.gz){
                        data.msg += status;
                        if(status.length === 5){
                            status = ".";
                        } else {
                            status += ".";
                        }
                    }
                    $(self).parent().prev().text(data.msg);
                    if(data.data.part){
                        $.get(self.href, 
                            {"part" : data.data.part, "start" : data.data.start}, 
                            success, 
                            "json"
                        );
                    }  else {
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
                   
				   layer.msg(data.msg);
                }
            }
        });



  })
</script>

{/block}